/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ThemeChooser.java
 *
 * Created on Aug 17, 2009, 11:53:27 AM
 */
package doghost.utils;

import doghost.DoghostApp;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.MetalTheme;
import org.jdesktop.application.Action;

/**
 *
 * @author duo
 */
public class ThemeChooser extends javax.swing.JDialog {

    /** Creates new form ThemeChooser */
    public ThemeChooser(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    @Action
    public void updateTheme() throws UnsupportedLookAndFeelException {
        if (jComboBox1.getSelectedItem().equals("Nimbus")) {
            try {
                UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(ThemeChooser.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                Logger.getLogger(ThemeChooser.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(ThemeChooser.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        /*else if (jComboBox1.getSelectedItem().equals("Substance")){

            try {
               // Define o look and feel
               UIManager.setLookAndFeel(new SubstanceMistSilverLookAndFeel());
               // Escurece o tema
               //SubstanceLookAndFeel.setCurrentTheme(new SubstanceCremeTheme().shade(0.1));
               // Define o watermark
               //SubstanceLookAndFeel.setCurrentWatermark(new SubstanceMetalWallWatermark());
               // Ajusta a forma dos botões
               //SubstanceLookAndFeel.setCurrentButtonShaper(new ClassicButtonShaper());
               // Gradient painters for buttons
               //SubstanceLookAndFeel.setCurrentGradientPainter(new WaveGradientPainter());
               // Faz com que o watermark vaze (bleed) por componentes opacos, como JTextField's
               // Note a área de texto da figura 7
               //UIManager.put(SubstanceLookAndFeel.WATERMARK_TO_BLEED, Boolean TRUE);
               // Ajusta localização e quantidade de botões da bara de rolagem (scrolbar)
               // Perceba na figura 7 que a scrolbar possui três botões
               UIManager.put(SubstanceLookAndFeel.SCROLL_PANE_BUTTONS_POLICY,
                              SubstanceConstants.ScrollPaneButtonPolicyKind.MULTIPLE);
               JDialog.setDefaultLookAndFeelDecorated(true);
            }  catch (UnsupportedLookAndFeelException ex) {
                ex.printStackTrace();
            }

        } */
        else {
            MetalTheme m = Theme.valueOf(this.jComboBox1.getSelectedItem().toString());
            MetalLookAndFeel.setCurrentTheme((MetalTheme) m);
            try {

                UIManager.setLookAndFeel(new MetalLookAndFeel());
                JFrame.setDefaultLookAndFeelDecorated(true);
                JDialog.setDefaultLookAndFeelDecorated(true);
            } catch (UnsupportedLookAndFeelException ex) {
                System.out.println("Cannot set new Theme for Java Look and Feel.");
            }
        }

        SwingUtilities.updateComponentTreeUI(DoghostApp.getApplication().getMainFrame());
        setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(doghost.DoghostApp.class).getContext().getActionMap(ThemeChooser.class, this);
        jButton1.setAction(actionMap.get("updateTheme")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Default", "Aqua", "Large Font", "Low Vision", "Nimbus", "Substance" }));
        jComboBox1.setName("jComboBox1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addContainerGap(284, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(142, 142, 142)
                .addComponent(jButton1)
                .addContainerGap(79, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                ThemeChooser dialog = new ThemeChooser(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    // End of variables declaration//GEN-END:variables
}
